package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;

/**
 * 
 *  @author lcs
 *  data 2017-03-26
 *
 */
@Entity()
//@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "T_DEMAND_CHANGE")
@BatchSize(size=20)
@Lazy(value=true)
//@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class DemandChange extends BasicModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4758965936642858073L;
	
	public static final Long DEMANDCHANGESTATE_DRAFT = 0L;
	public static final Long DEMANDCHANGESTATE_PASS = 1L;
	public static final Long DEMANDCHANGESTATE_DECLINE = 2L;
	
	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name="UNIQUEID")
	protected String uniqueId;
	
	// 更改单号
	@Column(name="CHANGEID")
	protected String changeId;
	
	/**
	 * 指令唯一号
	 */
	@Column(name="DEMANDUID")
	protected String demandUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="DEMANDUID",insertable=false,updatable=false)
	protected Demand demand;
	
	/**
	 * 更改后的交货期
	 */
	@Column(name="NEWLATEFINISH",length=7)
	protected Date newLateFinish;
	/**
	 * 原交货期
	 */
	@Column(name="OLDLATEFINISH",length=7)
	protected Date oldLateFinish;
	/**
	 * 更改后的齐套期
	 */
	@Column(name="NEWEARLYSTART",length=7)
	protected Date newEarlyStart;
	/**
	 * 原齐套期
	 */
	@Column(name="OLDEARLYSTART",length=7)
	protected Date oldEarlyStart;
	/**
	 * 更改后的需求数量
	 */
	@Column(name="NEWDUEQTY", precision=10, scale=0)
	protected Double newDueQty;
	/**
	 * 原需求数
	 */
	@Column(name="OLDDUEQTY", precision=10, scale=0)
	protected Double oldDueQty;
	/**
	 * 更改单状态
	 */
	@Column(name="CHANGESTATE", precision=10, scale=0)
	protected Long demandChangeState;
	/**
	 * 更改单状态描述
	 */
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="CHANGESTATE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'demandchangestate'", referencedColumnName="TYPESNAME"))
	})
	protected TypesData demandChangeStateDesc;
	/**
	 * 批准人
	 */
	@Column(name="APPROVER")
	protected String approver;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="APPROVER",insertable=false,updatable=false)
	protected Employee approverEmployee;

	/**
	 * 批准日期
	 */
	@Column(name="APPROVEDATE",length=7)
	protected Date approveDate;
	/**
	 * 变更原因
	 */
	@Column(name="CHANGEREASON")
	protected String changeReason;

	
	@Override
	public String getUuid() {
		return uniqueId;
	}
	@Override
	public void setUuid(String uuid) {
		this.uniqueId = uuid;
	}
	
	public String getUniqueId() {
		return uniqueId;
	}
	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}
	
	public String getChangeId() {
		return changeId;
	}
	public void setChangeId(String changeId) {
		this.changeId = changeId;
	}
	public String getDemandUid() {
		return demandUid;
	}
	public void setDemandUid(String demandUid) {
		this.demandUid = demandUid;
	}
	public Demand getDemand() {
		return demand;
	}
	public void setDemand(Demand demand) {
		this.demand = demand;
	}
	public Date getNewLateFinish() {
		return newLateFinish;
	}
	public void setNewLateFinish(Date newLateFinish) {
		this.newLateFinish = newLateFinish;
	}
	public Date getOldLateFinish() {
		return oldLateFinish;
	}
	public void setOldLateFinish(Date oldLateFinish) {
		this.oldLateFinish = oldLateFinish;
	}
	public Date getNewEarlyStart() {
		return newEarlyStart;
	}
	public void setNewEarlyStart(Date newEarlyStart) {
		this.newEarlyStart = newEarlyStart;
	}
	public Date getOldEarlyStart() {
		return oldEarlyStart;
	}
	public void setOldEarlyStart(Date oldEarlyStart) {
		this.oldEarlyStart = oldEarlyStart;
	}
	public Long getDemandChangeState() {
		return demandChangeState;
	}
	public void setDemandChangeState(Long demandChangeState) {
		this.demandChangeState = demandChangeState;
	}
	public TypesData getDemandChangeStateDesc() {
		return demandChangeStateDesc;
	}
	public void setDemandChangeStateDesc(TypesData demandChangeStateDesc) {
		this.demandChangeStateDesc = demandChangeStateDesc;
	}
	public String getApprover() {
		return approver;
	}
	public void setApprover(String approver) {
		this.approver = approver;
	}
	public Employee getApproverEmployee() {
		return approverEmployee;
	}
	public void setApproverEmployee(Employee approverEmployee) {
		this.approverEmployee = approverEmployee;
	}
	public Date getCreateTime() {
		return createTime;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public Date getApproveDate() {
		return approveDate;
	}
	public void setApproveDate(Date approveDate) {
		this.approveDate = approveDate;
	}
	public String getChangeReason() {
		return changeReason;
	}
	public void setChangeReason(String changeReason) {
		this.changeReason = changeReason;
	}
	public String getNotes() {
		return notes;
	}
	public void setNotes(String notes) {
		this.notes = notes;
	}
	public Double getNewDueQty() {
		return newDueQty;
	}
	public void setNewDueQty(Double newDueQty) {
		this.newDueQty = newDueQty;
	}
	public Double getOldDueQty() {
		return oldDueQty;
	}
	public void setOldDueQty(Double oldDueQty) {
		this.oldDueQty = oldDueQty;
	}
}
